package com.rc.saas.tenant;

import com.rc.saas.tenant.common.utils.MD5Utils;
import org.apache.commons.lang3.StringUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.io.IOException;

/**
 * HTM文件解析
 * Created by Sven on 2021/07/28
 */
public class JsoupHtmlParser {

    /**
     * JSP
     * @throws IOException
     */
    @Test
    void parseJSP() throws IOException {
        //从一个URL加载一个Document
        //Document doc = Jsoup.connect("https://saastenant.jin-zhuang.cn/jinzhuang-saas-tenant/orderInfo/totalDataIndex").get();
        //String title = doc.title();
        //Elements button = doc.select("button");
        //System.out.println(button);

        //从一个文件加载文档
        File input = new File("src/main/webapp/templates/sms/tenantSms.jsp");
        Document doc = Jsoup.parse(input, "UTF-8");

        String title = doc.title();
        Elements buttons = doc.select("button");

        System.out.println(buttons);

        for (Element button : buttons) {
            String onclick = button.attr("onclick");
            String text = button.text();

            System.out.println(text + "....." + onclick);
        }
    }

    /**
     * js
     * @throws IOException
     */
    @Test
    void parseJS() throws IOException {
        //从一个文件加载文档
        File input = new File("src/main/webapp/appjs/banner/appBanner.js");
        Document doc = Jsoup.parse(input, "UTF-8");

        String title = doc.title();
        Elements buttons = doc.select("a[onclick]");

        System.out.println(buttons);

        for (Element button : buttons) {
            String onclick = button.attr("onclick");
            String text = button.text();

            //方法名
            System.out.println(text + "....." + StringUtils.substringBefore(onclick, "("));
        }
    }
}
